package com.qs.education.controllers;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationHomeWorkResponse;
import com.qs.education.bean.beans.EducationHomeWorkStudentResponse;
import com.qs.education.bean.entity.EducationHomeWork;
import com.qs.education.bean.entity.EducationHomeWorkQuestion;
import com.qs.education.bean.entity.EducationHomeWorkStudent;
import com.qs.education.bean.enums.ResponseStatus;
import com.qs.education.service.IHomeWorkAPIService;

/**
 * @class HomeWorkController
 * @author Leon
 * @description
 * @date Nov 19, 2018
 */
@RestController
@RequestMapping("/homework")
public class HomeWorkController {

	@Autowired
	private IHomeWorkAPIService iHomeWorkAPIService;

	// -------------------------------------------------------------------------------------------------------------

	/**
	 * @author Warren
	 * @param studentId
	 * @return ResponseListBean<EducationHomeWorkStudent>
	 * @description 根据学生id查询学生的作业列表(作业本)
	 * @date Nov 20, 2018
	 */
	@RequestMapping("/getListByStudentIdAPI")
	public ResponseListBean<EducationHomeWorkStudent> getListByStudentId(Long studentId) {
		ResponseListBean<EducationHomeWorkStudent> responseListBean = iHomeWorkAPIService.getListByStudentId(studentId);
		return responseListBean;
	}

	/**
	 * @author Warren
	 * @param homeworkId
	 * @return ResponseListBean<EducationHomeWorkQuestion>
	 * @description 根据作业id获得作业的所有题目
	 * @date Nov 22, 2018
	 */
	@RequestMapping("/getALLQuestionByHomeWorkIdAPI")
	public ResponseListBean<EducationHomeWorkQuestion> getALLQuestionByHomeWorkId(Long homeworkId) {
		ResponseListBean<EducationHomeWorkQuestion> responseListBean = iHomeWorkAPIService
				.getALLQuestionByHomeWorkId(homeworkId);
		return responseListBean;
	}

	/**
	 * @author Warren
	 * @param hqId      作业问题标识
	 * @param studentId 学生id
	 * @param answerId  问题选项id
	 * @return ResponseBean
	 * @description
	 * @date Nov 22, 2018
	 */
	@RequestMapping("/answerHomeWorkQuestionAPI")
	public ResponseBean answerHomeWorkQuestion(Long hqId, Long studentId, Long answerId) {
		ResponseBean responseBean = null;
		try {
			responseBean = iHomeWorkAPIService.answerHomeWorkQuestion(hqId, studentId, answerId);
		} catch (Exception e) {
			responseBean = new ResponseBean();
			responseBean.setStatus(ResponseStatus.FAILED.toString());
		}
		return responseBean;
	}

	/**
	 * @author Warren
	 * @param homeworkId
	 * @param studentId
	 * @param startTime
	 * @param endTime
	 * @return ResponseBean
	 * @description 学生提交作业
	 * @date Nov 22, 2018
	 */
	@RequestMapping("/studentCommitHomeWorkAPI")
	public ResponseBean studentCommitHomeWork(Long homeworkId, Long studentId, String startTime, String endTime) {
		ResponseBean responseBean = null;
		try {
			responseBean = iHomeWorkAPIService.studentCommitHomeWork(homeworkId, studentId, startTime, endTime);
		} catch (Exception e) {
			responseBean.setMessage(ResponseStatus.FAILED.toString());
		}
		return responseBean;
	}

	// ------------------------------------------------------------------------------------
	/**
	 * @Description 教师选择群组发布作业
	 * @author Leon
	 * @date Nov 22, 2018
	 * @param
	 * @return ResponseBean
	 */
	@RequestMapping("/publishHomeWork")
	public ResponseBean publishHomeWork(@RequestParam(value = "questionIds") List<Long> questionIds,
			@RequestParam(value = "groupIds") List<Long> groupIds,
			@RequestParam(value = "lessonIds") List<Long> lessonIds, String startTime, String endTime,
			String teacherId) {
		ResponseBean response = new ResponseBean();
		try {
			iHomeWorkAPIService.publishHomeWork(questionIds, groupIds, lessonIds, startTime, endTime, teacherId);
			response.setStatus(ResponseStatus.SUCCESS.toString());
		} catch (Exception e) {
			response.setStatus(ResponseStatus.FAILED.toString());
			e.printStackTrace();
		}
		return response;
	}

	/**
	 * @Description 根据教师ID获取教师发布过的作业列表
	 * @author Leon
	 * @date Nov 23, 2018
	 * @param
	 * @return ResponseListBean<EducationHomeWork>
	 */
	@RequestMapping("/findHomeWorkByTeacherId")
	public ResponseListBean<EducationHomeWork> findHomeWorkByTeacherId(String teacherId) {
		ResponseListBean<EducationHomeWork> response = new ResponseListBean<EducationHomeWork>();
		response = iHomeWorkAPIService.findHomeWorkByTeacherId(teacherId);
		return response;
	}

	/**
	 * @Description 根据作业id 查看作业概览
	 * @author Leon
	 * @date Nov 26, 2018
	 * @param
	 * @return EducationHomeWork
	 */
	@RequestMapping("/findHomeWorkOverviewById")
	public EducationHomeWorkResponse findHomeWorkOverviewById(String id) {
		EducationHomeWorkResponse response = null;
		response = iHomeWorkAPIService.findHomeWorkOverviewById(id);
		return response;
	}

	/**
	 * @Description 根据作业id 删除作业
	 * @author Leon
	 * @date Nov 26, 2018
	 * @param
	 * @return ResponseBean
	 */
	@RequestMapping("/deleteHomeWorkById")
	public ResponseBean deleteHomeWorkById(String id) {
		ResponseBean response = new ResponseBean();
		try {
			response = iHomeWorkAPIService.deleteHomeWorkById(id);
			if(response.getStatus() == null ) {
				response.setStatus(ResponseStatus.SUCCESS.toString());
			}
		} catch (Exception e) {
			response.setStatus(ResponseStatus.FAILED.toString());
			e.printStackTrace();
		}
		return response;
	}
	
	/**
	 * @Description 获取学生作业概览
	 * @author Leon
	 * @date   Nov 27, 2018
	 * @param  
	 * @return EducationHomeWorkStudentResponse
	 */
	@RequestMapping("/getStudentHomeWorkOverview")
	public EducationHomeWorkStudentResponse  getStudentHomeWorkOverview(String id) {
		EducationHomeWorkStudentResponse response = null;
		return response;
	}
}
